package com.qiangesoft.ratelimit.utils;

import lombok.Data;

/**
 * 统一结果
 *
 * @author qiangesoft
 * @date 2024-02-27
 */
@Data
public class ResultVO {

    private Boolean success;
    /**
     * 响应提示信息
     */
    private String message;
    /**
     * 相应状态码
     */
    private Integer code;
    /**
     * 保存返回数据的对象
     */
    private Object data;

    /**
     * 请求成功
     */
    public static ResultVO ok() {
        return ok(null);
    }

    public static ResultVO ok(Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(true);
        resultVO.setCode(200);
        resultVO.setMessage("请求成功");
        resultVO.setData(data);
        return resultVO;
    }

    /**
     * 请求失败
     */
    public static ResultVO fail() {
        return fail("请求失败");
    }

    public static ResultVO fail(String message) {
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(false);
        resultVO.setCode(500);
        resultVO.setMessage(message);
        return resultVO;
    }

    @Override
    public String toString() {
        return "R{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", code=" + code +
                ", data=" + data +
                '}';
    }
}
